export const setExpire = (key, value, expire) => {
  const obj = {
    data: value,
    time: Date.now(),
    expire: expire
  }
  localStorage.setItem(key, JSON.stringify(obj))
}

export const getExpire = key => {
  let val = localStorage.getItem(key)
  if (!val) {
    return val
  }
  val = JSON.parse(val)
  if (Date.now() - val.time > val.expire) {
    localStorage.removeItem(key)
    return null
  }
  return val.value
}
